/*
 * @Author: 黑白灰01 3193273703@qq.com
 * @Date: 2025-01-27 12:58:10
 * @LastEditors: 黑白灰01 3193273703@qq.com
 * @LastEditTime: 2025-01-27 18:03:26
 * @FilePath: /hei_picture_web/src/request/request.ts
 * @Description: 请求配置
 */
import { message } from 'ant-design-vue'
import axios from 'axios'
const myAxios = axios.create({
  baseURL: 'http://localhost:8123',
  timeout: 50000,
  withCredentials: true,
})
myAxios.interceptors.request.use(
  (config) => {
    return config
  },
  (error) => {
    return Promise.reject(error)
  },
)
myAxios.interceptors.response.use(
  (response) => {
    const { data } = response
    if (data.code === 40100) {
      if (
        !response.request.responseURL.includes('user/get/login') &&
        !window.location.href.includes('/user/login')
      ) {
        message.error('请先登录')
        window.location.href = `/user/login?redirect=${window.location.href}`
      }
    }
    return response
  },
  (error) => {
    return message.error(error.message)
  },
)
export default myAxios
